package org.netwia.networks;

import java.io.InputStream;
import java.io.OutputStream;

/**
 * Defines functionality for reading and writing remote package from and into streams.
 * 
 * @author radek.hecl
 *
 * @param <T> parameter type
 */
public interface RemotePackageStreamer<T> {

    /**
     * Reads remote package from stream.
     * Stream will be moved. Client is still responsible for closing stream.
     * 
     * @param in input stream, bytes for the whole package must be available, stream is moved
     * @return remote package
     */
    public RemotePackage<T> readFromStream(InputStream in);
    
    /**
     * Writes remote package into stream.
     * Bytes will be written into stream. Caller is responsible for closing stream.
     * 
     * @param remotePackage remote package to be written
     * @param out output stream, must be open
     */
    public void writeToStream(RemotePackage<T> remotePackage, OutputStream out);
    
}
